<?php


namespace app\dao\query;


use app\model\User;

class UserQueryDao
{
    private $query;

    public function __construct()
    {
        $this->query = new User();
//        $this->query = $this->dataConversion();
    }

    /**
     * 单位转换
     * @return $this
     */
    public function dataConversion()
    {
        $this->query = $this->query->filter(function($query)
        {

        });

        return $this;
    }

    /**
     * 获取列表
     * @param int $page -
     * @param int $limit -
     * @return \think\Paginator -
     */
    public function getList(int $page = 1, int $limit = 10)
    {
        return $this->query->paginate([
            'list_rows' => $limit,
            'page' => $page
        ]);
    }

    /**
     * 获取所有数据
     * @return array -
     */
    public function getAll()
    {
        User::where()->select();
        return $this->query->select();
    }

    /**
     * 获取一个
     * @return mixed
     */
    public function getOne()
    {
        return $this->query->find();
    }


    /**
     * 获取当前筛选下的总记录数
     * @return int -
     */
    public function getCount()
    {
        return $this->query->count();
    }

    /**
     * 根据OpenId查询
     * @param String $openId
     * @return $this
     */
    public function filterByOpenId(String $openId) {
        if ($openId != null){
            $this->query = $this->query->where('wx_code', $openId);
        }
        return $this;
    }

    public function filterByUsername(String $username) {
        if ($username != null){
            $this->query = $this->query->where('username', $username);
        }
        return $this;
    }
}